﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;
using SQLToolbox.Types;


namespace SQLToolbox.Types
{
	public class SchemaObjectBase
	{
		public SchemaObjectType Type { get; set; }
		public string Name { get; set; }
	
	}

	public class SchemaObject : SchemaObjectBase
	{
		public Script Script { get; set; }
		public string Schema { get; set; }
		private Dictionary<string, object> requestedProperties = new Dictionary<string, object>();
		public IDictionary<string, object> RequestedProperties
		{
			get
			{
				return requestedProperties;
			}
		}

		private SchemaObjectsCollection attachedObjects = new SchemaObjectsCollection();
		public SchemaObjectsCollection AttachedObjects
		{
			get
			{
				return attachedObjects;
			}
		}
		public Script FullScript
		{
			get
			{
				Script scr = new Script(this.Script);
				foreach (var att in attachedObjects)
				{
					scr.AddRange(att.Script.ToArray());
				}
				return scr;
			}
		}
	}

	public class Schema
	{
		public SchemaObjectsCollection Tables { get; private set; }
		public SchemaObjectsCollection Views { get; private set; }
		public SchemaObjectsCollection Procedures { get; private set; }
		public SchemaObjectsCollection UserDefinedFunctions { get; private set; }
		public SchemaObjectsCollection UserDefinedTypes { get; private set; }
		public SchemaObjectsCollection UserDefinedDataTypes { get; private set; }
		public SchemaObjectsCollection Logins { get; private set; }

		public Schema()
		{
			Tables = new SchemaObjectsCollection();
			Views = new SchemaObjectsCollection();
			Procedures = new SchemaObjectsCollection();
			UserDefinedFunctions = new SchemaObjectsCollection();
			UserDefinedTypes = new SchemaObjectsCollection();
			UserDefinedDataTypes = new SchemaObjectsCollection();
			Logins = new SchemaObjectsCollection();
		}
	}

	public class SchemaObjectsCollection : List<SchemaObject>
	{
		public bool Contains(string name)
		{
			return this.ConvertAll((t) => { return t.Name; }).Contains(name);
		}
	}


}